package com.itboye.textileexpres.myset;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.textileexpes.adapter.MyOfflineOrderAdapter;
import com.itboye.textileexpes.beans.OfferLineOrderBeans;
import com.itboye.textileexpes.presenter.ShopCartPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseActivity;
import com.itboye.textileexpres.base.ResultEntity;

public class ActivityOfflineOrder extends BaseActivity implements
		OnClickListener, Observer {
	ExpandableListView expandlsitview;
	MyOfflineOrderAdapter adapter;
	ImageView back;
	TextView title;
	ImageView img_other;
	ShopCartPresenter cartPresenter;
	OfferLineOrderBeans beans;
	// OfferLineOrderBeans lineOrderBeans = new OfferLineOrderBeans();
	private String page_size = "10";
	private String page_index = "1";
	LinearLayout off_lin;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_offline_order;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		title.setText("线下订单");
		beans = new OfferLineOrderBeans();
		cartPresenter = new ShopCartPresenter(this);
		cartPresenter.onShopCharOrder("105", page_size, page_index);

		expandlsitview.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});
		expandlsitview.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});

	}

	public void onExpandGroup() {

		expandlsitview.setGroupIndicator(null);
		// 默认全部展开
		for (int i = 0; i < beans.getList().size(); i++) {
			expandlsitview.expandGroup(i);
			System.out.println(">>>>>>>>>>>>>>>执行了");
		}
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {

			if (entity.getEventType() == cartPresenter.ShopcarOrderSuccessEvent) {
				// toast("bbb"+entity.getData());
				beans = (OfferLineOrderBeans) entity.getData();
				adapter = new MyOfflineOrderAdapter(ActivityOfflineOrder.this,
						beans);
				expandlsitview.setAdapter(adapter);
				onExpandGroup();
				toast(beans.getList().get(0).getItem().get(0).getInfo().get(0)
						.getLoc_country()
						+ "");
			}
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;

		default:
			break;
		}
	}
}
